define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index:function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'trade/index',
                    multi_url: 'trade/multi',
                    table: 'trade_order',
                }
            });

            var table = $("#table");
            var tableOptions = {
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                pagination: false,
                commonSearch: false,
                search: false,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'uid', title: __('Uid')},
                        {field: 'seller_username', title: __('SellerName')},
                        {field: 'to_uid', title: __('BuyerId')},
                        {field: 'buyer_username', title: __('BuyerName')},
                        {field: 'name', title: __('PetsName')},
                        {field: 'num', title: __('PetsNum')},
                        {field: 'amount', title: __('TotalPrice'), operate: false, formatter:function (value, row, index) {
                                return value + ' U';
                            }},
                        {field: 'status_str', title: __('Status'), operate: false},
                    ]
                ]
            };
            // 初始化表格
            table.bootstrapTable(tableOptions);

            // 为表格绑定事件
            Table.api.bindevent(table);

            //绑定TAB事件
            $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
                // var options = table.bootstrapTable(tableOptions);
                var typeStr = $(this).attr("href").replace('#', '');
                var options = table.bootstrapTable('getOptions');
                options.pageNumber = 1;
                options.queryParams = function (params) {
                    return params;
                };
                table.bootstrapTable('refresh', {});
                return false;

            });
        },
        api: {
            bindevent: function () {
                $(document).on("change", "#c-type", function () {
                    $("#c-pid option[data-type='all']").prop("selected", true);
                    $("#c-pid option").removeClass("hide");
                    $("#c-pid option[data-type!='" + $(this).val() + "'][data-type!='all']").addClass("hide");
                    $("#c-pid").data("selectpicker") && $("#c-pid").selectpicker("refresh");
                });
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
